package hs.framework.opcClient.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import hs.framework.opcClient.entity.TypeClass;
import hs.framework.opcClient.mapper.TypeClassMapper;
import hs.framework.opcClient.service.ITypeClassService;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Description 数据类型转换表，用于对接数据类型 服务实现类
 * @Author sxmz
 * @Date 2021/5/13 0013 上午 11:21
 */
@Service
@Log4j2
public class TypeClassServiceImpl extends ServiceImpl<TypeClassMapper, TypeClass> implements ITypeClassService {
    private static HashMap<String,String> typeMap = new HashMap<>();

    @Override
    @PostConstruct
    public void init(){
        log.info("开始类型转换记录map初始化...");
        List<TypeClass> list = baseMapper.selectList(null);
        for (TypeClass tc: list){
            typeMap.put(tc.getTypeName(),tc.getTypePath());
        }
        log.info("类型转换记录map初始化完成!");
    }

    @Override
    public IPage<TypeClass> selectTypeClassPage(IPage<TypeClass> page, TypeClass typeClass) {
        return page.setRecords(baseMapper.selectTypeClassPage(page, typeClass));
    }

    public static String getClassPath(String typeName){
        return typeMap.get(typeName);
    }
}
